<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title></title>
    <style>
        html, body {
            margin: 0;
            padding: 0;
        }
    </style>
</head>
<body>

</body>
<script>

    var arr = [
        {userId:'12'},
        {userId:'23'},
        {userId:'34'},
        {userId:'45'}
    ];

    var userId = '1' ;

    arr.forEach(function(v , i){
        if(userId){
            //模糊查询,判断用户输入userId是否和v.userId前几个字符一样
            if( v.userId.indexOf(userId) == 0 ){
                console.log(v);
            }
        }
    })


</script>
</html>